import java.util.Stack;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: lenovo
 * Date: 2023 -04 -11
 * Time: 23:03
 */
public class Solution {
    public static boolean isValid(String s) {
        Stack<Character> stack=new Stack<>();
        for(int i=0;i<s.length();i++){
            char ch=s.charAt(i);
            if(ch=='('||ch=='{'||ch=='['){
                stack.push(ch);
            }else{
                //右括号
                if(stack.empty()){
                    return false;
                }
                char tmp=stack.peek();
               if(tmp=='('&&ch==')'||tmp=='{'&&ch=='}'||tmp=='['&&ch==']'){
                   stack.pop();
               }else{
                   return false;
               }
            }
        }
        if(!stack.empty()){
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        String s=")(";
        Boolean ret=isValid(s);
        System.out.println(ret);
    }
}
